/**
 * @param {number[]} nums
 * @return {number}
*/
var majorityElement = function(nums) {
  let current = nums[0], count = 1;
  for(let i = 1; i < nums.length; i++) {
    if(!count) {
      current = nums[i];
      count = 1;
      continue;
    }
    if(nums[i] == current) {
      count++
    } else {
      count--;
    }
  }
  return current;
};
let nums = [3,2,3];
console.log(majorityElement(nums));
nums = [2,2,1,1,1,2,2];
console.log(majorityElement(nums));
